package jge;

/** The base object class
 * Every object has a position
 * and a picture.
 * Functions are given to find
 * the various values, aswell as
 * setting them. 
 * Objects can be tested for
 * collisions with other objects
 * or just a single point.
 * 
 * 
 * @author Andrew
 * LAST UPDATED - Andrew 5/02/12
 */

public abstract class Object {

	// x position
	public double x;

	// y position
	public double y;

	// sprite (picture)
	public Sprite sprite;

        // new object Takes a sprite, and a 2d position (x,y)
	public Object(Sprite sprite, double x, double y) {
		this.sprite = sprite;
		this.x = x;
		this.y = y;
	}

        // Returns Objects Width
        public double getWidth() {
            return sprite.getWidth();
        }
        
        // Returns Objects Height
        public double getHeight() {
            return sprite.getHeight();
        }
        
        // Draw it on the screen at its position
	public void draw() {
		sprite.draw((double) x, (double) y);
	}

        // return the x position of the object
	public double getX() {
		return (double) x;
	}

        // return the y position of the object
	public double getY() {
		return (double) y;
	}


        // checks for collision between object and a single point
        public boolean checkHit(double hitx,double hity) {
        // if the hit is in between the x coords and between the y coords it must
        // hit the rectangle.
        if((hitx>=x && hitx<=(x+sprite.getWidth())) && (hity<=y && hity>=(y-sprite.getHeight()))) return true;
        else return false;       
        }
        
        // Checks for collision between two objects
        public boolean checkCollision(Object target) {
            if(target.checkHit(x, y)==false &&                         // Is the top left corner in the target?
               target.checkHit(x, y - sprite.getHeight()) == false &&  // Is the bottom left corner?
               target.checkHit(x+sprite.getWidth(), y) == false &&     // Is the top Right corner?
               target.checkHit(x+sprite.getWidth(), y - sprite.getHeight()) == false) {  // Is the bottom Right corner? 
                 return false;
            }
            else return true;
        }
        
        // Checks to see if object is on the screen 
        // NOTE: Will change if screen size does
        //       Please make sure to update this 
        //       function
        
        // Inputs are the screen width and height
        public boolean inBounds(int screenx, int screeny) {
            if(getX() < screenx - 110
         && getX() > -(getWidth())
         && (getY()) < screeny - 100
         && getY() > -(getHeight())) return true;
            else return false;
        }
}